package com.xuexiang.xui_lib.util;

import ohos.aafwk.ability.Ability;
import ohos.agp.utils.Color;
import ohos.agp.window.service.WindowManager;
import ohos.app.Context;

/**
 * 状态栏操作工具类
 *
 * @since 2021-03-24
 */
public class StatusBarUtils {
    /**
     * 沉浸式状态栏
     */
    public static void translucent() {
        WindowManager.getInstance().getTopWindow()
            .ifPresent(window -> window.addFlags(WindowManager.LayoutConfig.MARK_TRANSLUCENT_STATUS));
    }

    /**
     * 设置状态栏黑色字体图标，
     *
     * @return return
     */
    public static boolean setStatusBarLightMode() {
        return false;
    }

    /**
     * 设置状态栏白色字体图标
     *
     * @return return
     */
    public static boolean setStatusBarDarkMode() {
        return false;
    }

    /**
     * 获取状态栏的高度。
     *
     * @param context context
     * @return return
     */
    public static int getStatusBarHeight(Context context) {
        return -1;
    }

    /**
     * 获取底部导航条的高度
     *
     * @param context 上下文
     * @return 底部导航条的高度
     */
    public static int getNavigationBarHeight(Context context) {
        return -1;
    }

    /**
     * 全屏
     */
    public static void fullScreen() {
        WindowManager.getInstance().getTopWindow()
            .ifPresent(window -> window.addFlags(WindowManager.LayoutConfig.MARK_FULL_SCREEN));
    }

    /**
     * 取消全屏
     */
    public static void cancelFullScreen() {
        WindowManager.getInstance().getTopWindow()
            .ifPresent(window -> window.clearFlags(WindowManager.LayoutConfig.MARK_FULL_SCREEN));
    }


    /**
     * 设置状态栏颜色
     *
     * @param ability
     * @param colorStr
     */
    public static void setStatusBarColor(Ability ability, String colorStr) {
        setStatusBarColor(ability, Color.getIntColor(colorStr));
    }

    /**
     * 设置状态栏颜色
     *
     * @param ability
     * @param color
     */
    public static void setStatusBarColor(Ability ability, int color) {
        if (ability != null) {
            ability.getWindow().setStatusBarColor(color);
        }
    }

}
